package com.ls.code01;

import java.util.Objects;

/**
 * @author LS
 * @version 1.0
 * @description: 单向链表
 * @date 2021/5/4 下午8:40
 */
public class SimpleLinkedList<E> {
    private Node<E> head = new Node<>();  //头节点
    private int size = 0; //大小

    private Boolean isEmpty() {
        return size == 0;
    }

    private static class Node<E> {
        private E value;
        private Node<E> next;

        public Node() {
        }

        public Node(E value, Node<E> next) {
            this.value = value;
            this.next = next;
        }

    }

    public void add(E e) {
        Node<E> newNode = new Node<>(e, null);
        if (isEmpty()) {
            head.next = newNode;
        } else {
            Node<E> temp = head;
            while (true) {
                if (temp.next == null) {
                    break;
                }
                temp = temp.next;
            }
            temp.next = newNode;
        }
        size++;
    }
}

class Demo2 {
    public static void main(String[] args) {
        SimpleLinkedList<String> stringSimpleLinkedList = new SimpleLinkedList<>();
        stringSimpleLinkedList.add("张三");
        stringSimpleLinkedList.add("李四");
        stringSimpleLinkedList.add("王五");
        System.out.println(stringSimpleLinkedList);
    }

}
